--
-- Author: shunguo.chen
-- Date: 2017-12-26 18:46:25
--
-- PvpRender pvp玩法

local ClassRef = app.mvc.createRenderClass(...)

local NUM_STR = L("tips_1150031")
local BALANCE_STR = L("tips_1150032")
local POWER_STR = L("tips_1150033")

--data = "teamTarget_surface" conf
function ClassRef.createWithData(data, node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.NewNodeTypeNode))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
	self.super.init(self, data)

	self:setContentSize(self._ui.Panel:getContentSize())

    self._ui.Panel_dungeons:setVisible(false)
    self._ui.Panel_activity:setVisible(false)
    self._ui.Panel_time:setVisible(false)

	display.uiAddClick(self._ui.Panel, function(sender, eventType)
	    executeFunc(self._onClick, self)
	end, true, 0.02)

    self._markBg = self._ui["Panel/Panel_mark/bg"]
    self._markText = self._ui["Panel/Panel_mark/num"]

    self._tltText = self._ui["Panel/Panel_match/tlt"]
    self._descText = self._ui["Panel/Panel_match/text"]

    self._ui.first:setVisible(true)

	self:refresh()
end

function ClassRef:refresh()
	if self._data then
		local data = self._data
        self._markText:setString(string.format(NUM_STR, data.showNum))
        self._tltText:setString(L(data.name))
        self._descText:setString(L(data.desc))
        self:setIcon(Res.teamtarget_pic .. data.banner .. ".png")
	end
end

function ClassRef:setIcon(res)
    self._ui.img:loadTexture(res)
end

function ClassRef:setFirstWin(b)
    self._ui.first:setVisible(b)
end

function ClassRef:setClickEnable(b)
	self._ui.Panel:setTouchEnabled(b)
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
